<template>
    <div class="full-height">
        <el-container class="full-height">
            <el-header class="full-header">
                <el-menu :default-active="activeIndex" class="el-menu-demo" background-color="#ffffff"
                    text-color="#303133" mode="horizontal" @select="handleSelect">
                    <el-menu-item index="/">home</el-menu-item>
                    <el-submenu index="2">
                        <template slot="title">page1</template>
                        <el-menu-item index="2-1">选项1</el-menu-item>
                        <el-menu-item index="2-2">选项2</el-menu-item>
                        <el-menu-item index="2-3">选项3</el-menu-item>
                        <el-submenu index="2-4">
                            <template slot="title">选项4</template>
                            <el-menu-item index="2-4-1">选项1</el-menu-item>
                            <el-menu-item index="2-4-2">选项2</el-menu-item>
                            <el-menu-item index="2-4-3">选项3</el-menu-item>
                        </el-submenu>
                    </el-submenu>
                    <el-menu-item index="/page2">page2</el-menu-item>
                    <el-menu-item index="/page3">page3</el-menu-item>
                </el-menu>
            </el-header>
            <el-main>
                <router-view></router-view>
            </el-main>
            <el-footer class="custom-footer">
                &copy; 2024 Your Company. All rights reserved.
            </el-footer>
        </el-container>
    </div>
</template>


<script>
export default {
    name: 'LayoutComponent',
    data() {
        return {
            activeIndex: this.$route.path // 设置默认激活的菜单项为当前路径
        };
    },
    watch: {
        $route(to) {
            console.log("route", to.path)
            this.activeIndex = to.path; // 路由改变时更新激活的菜单项
        }
    },
    methods: {
        handleSelect(key) {
            console.log("handleSelect", key)
            this.$router.push(key); // 跳转到选中的路由
        }
    },

};
</script>



<style lang="less">
html,
body,
.full-height {
    height: 100%;
    margin: 0;
    padding: 0;
}

.el-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.el-header {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
    padding: 0 !important;
    line-height: 60px;
    flex-shrink: 0;
    /* 保证header不收缩 */
}

.el-main {
    background-color: #E9EEF3;
    color: #333;
    flex-grow: 1;
    /* 使main占据剩余空间 */
    overflow: auto;
    padding: 0 !important;
    /* 当内容过多时，可以滚动 */
}


.custom-footer {
    background-color: #f0f0f0;
    /* 更柔和的背景颜色 */
    color: #333;
    /* 字体颜色 */
    text-align: center;
    line-height: 60px;
    flex-shrink: 0;
    padding: 10px 20px;
    /* 增加内边距 */
    box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
    /* 增加阴影 */
    font-size: 16px;
    /* 改变字体大小 */
    font-family: 'Helvetica Neue', Arial, sans-serif;
    /* 改变字体样式 */
}
</style>
